Editor.DraggerResize = function () {
	var inix;
	var iniy;
	var dx;
	var dy;
	var shape;
	var impl;
	var isActive;
	var figResize;
	var figFrame;
	return {
		init: function (s) {
			shape = s;
			impl = shape.getImplementation();
			isActive = false;
		},
		mouseover: function () {
			if (!Editor.Util.isDragging()) {
				figResize.attr(Editor.CONFIG.VISIBLE_ATTR);
			}
		},
		mouseout: function () {
			if (!Editor.Util.isDragging()) {
				figResize.attr(Editor.CONFIG.UNVISIBLE_ATTR);
			}
		},
		remove: function () {
			figResize.remove();
			delete figResize;
		},
		draw: function () {
			figResize = Editor.STATE.CANVAS.path(Editor.CONFIG.FIGRESIZE_PATH).attr(Editor.CONFIG.FIGRESIZE_ATTR);
			figResize.translate(shape.getWidth() - Editor.CONFIG.FIGRESIZE_DELTA, shape.getHeight() - Editor.CONFIG.FIGRESIZE_DELTA);
			figResize.mouseover(shape.getDraggerResize().mouseover);
			figResize.mouseout(shape.getDraggerResize().mouseout);
			figResize.mousedown(shape.getDraggerResize().mousedown);
			figResize.toFront();
		},
		redraw: function () {
			figResize.translate(-figResize.getBBox().x, -figResize.getBBox().y);
			figResize.translate(shape.getX(), shape.getY());
			figResize.translate(shape.getWidth() - Editor.CONFIG.FIGRESIZE_DELTA, shape.getHeight() - Editor.CONFIG.FIGRESIZE_DELTA);
		},
		mousedown: function (e) {
			if (!Editor.Util.isDragging()) {
				shape.toFront();
				dx = e.clientX;
				dy = e.clientY;
				inix = e.clientX;
				iniy = e.clientY;

				impl.unselect();
				figFrame = impl.frameResize();
				Editor.STATE.DRAGGER = shape.getDraggerResize();
				isActive = true;
				figResize.toFront();
			}
		},
		onmousemove: function (e) {
			var dX = e.clientX - dx;
			var dY = e.clientY - dy;
			var w = figFrame.getBBox().width + dX;
			var h = figFrame.getBBox().height + dY;
			//if (w > Editor.CONFIG.SHAPE_MIN_WIDTH) {
			if (w >= impl.getMinWidth()) {
				figResize.translate(dX, 0);
				dx = e.clientX;
				figFrame.attr({
					width: w
				})
			}
			//if (h > Editor.CONFIG.SHAPE_MIN_HEIGHT) {
			if (h >= impl.getMinHeight()) {
				figResize.translate(0, dY);
				dy = e.clientY;

				figFrame.attr({
					height: h
				})
			}
			figResize.toFront();
		},
		onmouseup: function () {
			figFrame.remove();
			delete figFrame;
			var varX = dx - inix;
			var varY = dy - iniy;
			figResize.translate(-varX, -varY);
			figResize.attr(Editor.CONFIG.UNVISIBLE_ATTR);
			if (Editor.CONFIG.GRID_SNAP) {
				varX = Math.round(varX / Editor.CONFIG.GRID_SIZE) * Editor.CONFIG.GRID_SIZE;
				varY = Math.round(varY / Editor.CONFIG.GRID_SIZE) * Editor.CONFIG.GRID_SIZE;
			}
			impl.resize(varX, varY);
			isActive = false;
			Editor.STATE.DRAGGER = undefined;
		},
		translate: function (deltaX, deltaY) {
			figResize.translate(deltaX, deltaY);
		},
		isActive: function () {
			return isActive;
		},
		toFront: function () {
			figResize.toFront();
		}
	}
}
